
GAMERILE = "GameRule_";

//创建房间管理器
cc.Class({
    extends: cc.BaseClass,

    properties: {
        prefabs:[cc.Prefab], //[卡五星，跑得快]
        content : cc.Node,
        atlas: cc.SpriteAtlas
    },

    start () {
       
    },

    //初始化数据
    initData:function(){
        this.initNodePool();
    },

    initNodePool:function(){
        this.poolArr = {};
        for(var i = 0; i < this.prefabs.length; i++){
            var name = this.prefabs[i].name;
            this.poolArr[name] = new cc.NodePool();
            var node = cc.instantiate(this.prefabs[i]);
            this.poolArr[name].put(node);
        }
    },

    createNode:function(parentNode,idx){
        let node = null;
        var item = this.prefabs[idx];
        var name = item.name;
        if(this.poolArr[name].size() > 0){
            node = this.poolArr[name].get();
        }else{
            node = cc.instantiate(item);
        }
        node.parent = parentNode;
        this.content.height = node.height;
    },

    initView:function(kindId){
        this.initData();

        for(let i = 0; i < this.content.childrenCount;i++){
            var temp = this.content.children[0];
            temp && temp.destroy();
        }
        if(kindId == 62007){
            this.createNode(this.content,0);
        }
    },

    onBtnClickCallBack:function(event,cunstomData){
        var type = cunstomData;
        if(type == "createRoom"){
            this.onCreateRoom();
        }
    },

    onCreateRoom:function(){  
        var createItem = this.content.children[0];
        var ruleData = createItem.getComponent(createItem.name).getRuleAndBaseScore();

        var obj = new CMD_GP_C_CreateRoom();
        obj.dwID            = 0,
        obj.dwUserID        = g_GlobalUserInfo.GetGlobalUserData().dwUserID,
        obj.dwBaseRate      = ruleData.baseScore,
        obj.wKindID         = ruleData.wKindID,
        obj.dwRules         = ruleData.dwRules,
        obj.dwClubID        = 0,
        obj.dwMyClubID      = 0,
        obj.szRoomName      = ruleData.szRoomName

        cc.sys.localStorage.setItem(GAMERILE+ruleData.wKindID,JSON.stringify(ruleData));
        HallEvent.createRoom(this,obj);
    },
});
